package com.mission.game.playgame;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import com.mission.game.utils.Task;

public abstract class PlayAbstractTask extends Activity {

	protected Task _task;
	protected TextView _taskNameView;
	protected TextView _taskDescriptionView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(getContentView());
		
		_taskDescriptionView = (TextView) findViewById(getDescriptionInput());
		_taskNameView = (TextView) findViewById(getNameInput());
		
		Bundle extras = getIntent().getExtras();
		if (extras != null && extras.containsKey("task")) {
			_task = (Task) extras.getSerializable("task");
			setFields();
		}
	}

	protected abstract int getContentView();
	protected abstract int getNameInput();
	protected abstract int getDescriptionInput();

	protected void setFields() {
		_taskNameView.setText(_task.getName());
		_taskDescriptionView.setText(_task.getDescription());
		setSpecificFields();
	}

	protected abstract void setSpecificFields();
	public abstract void onBackToMissionClicked(View v);
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
	    if ((keyCode == KeyEvent.KEYCODE_BACK)) { //Back key pressed
	    	setResult(Activity.RESULT_CANCELED);
	    }
	    return super.onKeyDown(keyCode, event);
	}

}
